package cn.good.biz.service;

import cn.good.dto.Page;
import cn.good.mapper.IssueMapper;
import cn.good.pojo.Issue;
import cn.good.service.IssueService;
import cn.good.utils.Constant;
import cn.good.vo.IssueListVO;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service(interfaceClass = IssueService.class)
@Component
public class IssuesServiceImpl implements IssueService {

    @Resource
    private IssueMapper issueMapper;

    /**
     * 保存问题
     * @param issue
     * @return
     */
    @Override
    public Integer saveIssue(Issue issue) {
        return issueMapper.insertSelective(issue);
    }

    /**
     * 分页查询
     * @param issue
     * @param pageNo
     * @return
     */
    @Override
    public IssueListVO selectListByPage(Issue issue, Integer pageNo) {

        int count = issueMapper.selectCountByIssue(issue);

        Page page = new Page(pageNo, Constant.PAGE_NO,count);
        List<Issue> issueList = issueMapper.selectByIssue(issue,page.getBeginPos(),page.getPageSize());
        IssueListVO listVO = new IssueListVO();
        listVO.setPageCount(page.getPageCount());
        listVO.setTotal(count);
        listVO.setDate(issueList);
        return listVO;
    }

    /**
     * 根据id查询问题
     * @param id
     * @return
     */
    @Override
    public Issue selectBuId(Integer id) {

       return issueMapper.selectByPrimaryKey(Long.parseLong(id.toString()));

    }
}
